#ifndef _ROBOT_USER_H_
#define _ROBOT_USER_H_

#include "Lock.h"
#include <map>
#include <string>

enum EState
{
    E_State_None = 0,
    E_State_Login,
    E_State_GetServerList,
    E_State_EnterGame,
    E_State_InGame,
};
struct GameData
{
    GameData() : session(NULL)
    {
    }
    u64 id;
    std::string account;
    std::string passwd;
    u64 userid;
    u64 roleid;
    std::string sessionid;
    std::string ip;
    s32 port;
    s32 state;
    s64 recharge;
    void *session;
};

class CRobotUserManager
{
    SINGLETON_CLASS_DEFINE(CRobotUserManager);
public:
    void Init();
    bool HasRobot(const std::string &account);
    void CreateRobot(const std::string &account, const std::string &passwd, s32 recharge);
    void DestoryRobot(const std::string &account);
    void UpdateRobot(const std::string &account, s32 recharge);
    void UpdateRobot(const std::string &account, u64 userid, const std::string &sessionid);
    void UpdateRobot(const std::string &account, u64 roleid, const std::string &ip, s32 port);
    void UpdateRobot(const std::string &account, void *session);

    u64 GetId(const std::string &account);
    const char* GetPasswd(const std::string &account);
    u64 GetUserId(const std::string &account);
    const char* GetSessionId(const std::string &account);
    const char* GetIp(const std::string &account);
    s32 GetPort(const std::string &account);
    s32 GetState(const std::string &account);
    s64 GetRecharge(const std::string &account);
    s64 GetRoleId(const std::string &account);
    const char* GetAccount(u64 id);
    void* GetSession(const std::string &account);

    void RobotsHeartBeat();

private:
    u64 m_id;
    SGLib::CLock m_Lock;
    std::map<std::string, GameData*> m_robots;
    std::map<u64, std::string> m_robotsIdx;
};

#endif

